<?

require_once  $_SERVER['DOCUMENT_ROOT']."/../_lib/base/common.php";
require_once SITE_ROOT_PATH."/_lib/classes/class.template.php";
require_once SITE_ROOT_PATH."/_lib/classes/class.exchange_rates.php";
require_once SITE_ROOT_PATH."/_lib/classes/class.holidays.php";

	$template = new template();
	$template->title = "Currency Converter, Late Deals Ireland";
	$template->section_highlight = "home";
	$template->left_col = true;
	$template->breadcrumbs_html = "</li><li>&rsaquo;</li><li><a href=\"/currency_converter.html\">Currency Converter</a></li>";
	$template->ld_head();	
	
	
// FUNCTION // Display form ================================================
function display_form(){

$currency_array = explode(",", $_REQUEST['currency']);


$total = $_REQUEST['amount'] * $currency_array[0];

$total = number_format($total, 2, '.', '');

?>



<h2 title="Currency Converter">Currency Converter</h2>


<script type="text/javascript">


function calc_rate(){

	var x = document.getElementById("currency").selectedIndex;
	var rate = document.getElementsByTagName("option")[x].value;
	var amount = document.getElementById("amount").value;
	var total = (rate * amount);
	
	document.getElementById("total").value = total;

}



</script>


<?

	if($_REQUEST['amount']){

?>
<h3 class="title_plain"><?= $_REQUEST['amount']." Euro = ".$total." ".$currency_array[1]; ?></h3>
<? } ?>


<form action="<?= $_SERVER['PHP_SELF'] ?>" method="post">

<input type="hidden" name="action" value="calculate" />

<table class="cheap_holidays">
<tr>
	<td width="120"><label>Amount in Euros:</label></td>
	<td><input type="text" name="amount" value="1.00" /></td>
</tr>
<tr>
	<td><label>Currency:</label> </td>
	<td>
<select name="currency">
<?

$exchange_rates = new exchange_rates();
$all_rates = $exchange_rates->get_all_rates(true);

foreach($all_rates as $value){

?>
<option value="<?= $value['rate'].",".$value['name'] ?>"><?= $value['name'] ?></option>
<? } ?>
</select>

<input type="hidden" name="currency_name" id="currency_name" value="" />


</td>
</tr>
<tr>
	<td></td>
	<td><input type="submit" value="submit" name="submit" /></td>
</tr>
</table>


</form>






<?
}
// END FUNCTION =============================================================



switch ($_REQUEST['action']){
	default:
		display_form();
	break;
	case "calculate";
		display_form();
	break;
}



	$template->ld_foot();
	
?>